﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace NeonMika.Webserver.ClientLibrary
{
    public class DigitalPin : Pin
    {
        private bool isPWM;
        public bool IsPWM
        {
            get { return isPWM; }
            set
            {
                isPWM = value;
                OnPropertyChanged("IsPWM");
            }
        }

        private int duration;

        public int Duration
        {
            get { return duration; }
            set
            {
                duration = value;
                OnPropertyChanged("Duration");
            }
        }

        private int period;

        public int Period
        {
            get { return period; }
            set
            {
                period = value;
                OnPropertyChanged("Period");
            }
        }

        public string Switch()
        {
            return netduino.SwitchPin(id);
        }

        public string Set(bool state)
        {
            return netduino.SetDigitalPin(id, state);
        }

        public string SetPWM()
        {
            if (isPWM)
                return netduino.SetPWM(id, duration, period);
            else
                return "";
        }

        public DigitalPin(int id, bool isPwm, Netduino netduino)
            : base(id, netduino)
        {
            this.isPWM = isPwm;
        }
    }
}
